<template>
	<view class="load" v-if="!load">
		<u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon>
	</view>
	<view v-else>
		<x-scroll :fixed="true" @onRefresh="onRefresh" @scrolltolower="scrolltolower" :refresh="_freshing">
			<view class="list" v-if="Array.isArray(list) && list.length > 0">
				<view class="item wap" v-for="item in list" :key="item.UserID">
					<view class="cover">
						<image :src="item.HeadImgUrl" mode="aspectFill" />
					</view>
					<view class="con" @click="nav_to(`/pages/user/user_visitor?id=${item.UserID}`)">
						<view class="name f1 c1">
							{{ item.Name || '' }}
							<view class="member member_he" v-if="getUserType(item.UserType) == 1">黑金卡</view>
							<view class="member number_huan" v-if="getUserType(item.UserType) == 2">金卡</view>
							<view class="member number_yin" v-if="getUserType(item.UserType) == 3">银卡</view>
						</view>
						<view class="time f2 c3">{{ getOnlineTime(item.UpdateTime) }}在线</view>
					</view>
					<view class="btn_sm" @click="toChat(item)">发私信</view>
				</view>
			</view>
			<block v-else>
				<u-empty
					mode="list"
					width="64"
					height="64"
					icon="https://golfdate.oss-cn-shenzhen.aliyuncs.com/community/20230510114106.png"
					:show="true"
					iconSize="32"
					text="暂无好友"
				></u-empty>
			</block>
		</x-scroll>
	</view>
</template>

<script>
export default {
	data() {
		return {
			isLook: false,
			load: false,
			_freshing: true,
			newNum: 0,
			list: []
		};
	},
	onLoad(args) {
		this.init();
	},
	// onShow(){
	//     this.init();
	// },
	methods: {
		onRefresh() {
			this.init();
		},
		async init() {
			let res = await this.$api.post('/Team/MyTeamUsers');
			console.log(JSON.stringify(res.data));
			this.list = res.data;
			console.log(JSON.stringify(this.list));
			this.load = true;
		},
		toChat(item) {
			const convInfo = {
				id: item.ID + '',
				type: 0,
				name: item.Name
			};
			this.$im.clearNum(convInfo.id, item.type);
			const preid = uni.$prefix + convInfo.id;
			this.nav_to(`/pages/im/chat?id=${preid}&type=${convInfo.type}&name=${convInfo.name}`);
		}
	},
	computed: {
		getUserType(l) {
			return (l) => {
				if (l.indexOf('黑金') != -1) {
					return 1;
				} else if (l.indexOf('金') != -1) {
					return 2;
				} else if (l.indexOf('银') != -1) {
					return 3;
				} else {
					return 0;
				}
			};
		},
		getOnlineTime(time) {
			return (time) => {
				console.log(time);
				let d = new Date(time).valueOf();
				return uni.$u.timeFrom(d);
			};
		}
	}
};
</script>

<style lang="scss">
.list {
	.item {
		display: flex;
		height: 140rpx;
		align-items: center;
		.cover {
			height: 100rpx;
			width: 100rpx;
			border-radius: 50%;
			overflow: hidden;
			border: 1px solid #333;
			image {
				height: 100%;
				width: 100%;
			}
		}
		.con {
			padding-left: 20rpx;
			flex: 1;
			.time {
				margin-top: 10rpx;
			}
		}
		.btn_sm {
			width: 112rpx;
			height: 48rpx;
			border-radius: 8rpx;
			line-height: 48rpx;
			text-align: center;
			background: #606060;
			color: #fff;
		}

		.member {
			display: inline-block;
			vertical-align: middle;
			width: 68rpx;
			height: 32rpx;
			background: linear-gradient(135deg, #7e7e7e 0%, #292929 100%);
			border-radius: 2px;
			border: 2px solid #d6c6ab;
			text-align: center;
			color: #fff;
			font-size: 16rpx;
			line-height: 32rpx;
			margin-left: 20rpx;
		}
		.number_huan {
			color: #4c310c;
			background: linear-gradient(180deg, #fdf9f6 0%, #e1c4a6 100%);
			border: 2rpx solid #e6ceb5;
		}
		.number_yin {
			color: #4c310c;
			background: linear-gradient(180deg, #c9daf8 0%, #e1c4a6 100%);
			border: 2rpx solid #e6ceb5;
		}
	}
	.add {
		//  background: linear-gradient(90deg, #212121 0%, #313131 100%);
		.cover {
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				height: 70%;
				width: 70%;
			}
		}
		.nums {
			height: 45rpx;
			width: 45rpx;
			border-radius: 50%;
			background: #f00;
			color: #fff;
			text-align: center;
			line-height: 40rpx;
		}
	}
}
</style>
